/*-------------------<-- Start of Description -->--------------------\ | Generate random variate from a normal distribution | |-----------------------------------------| |--------------------------------------------------------------------| |-------------------------| | Arguments Need: | | seed - seed; Required, default is the current system time; | | var - the variable to save the generated random variates; | | mean - the mean of the normal distribution; | | std - the std of the distribution; | | temp - the temporary variable to update the seed; | | default is _rannor0_; | |---------------------------| |--------------------------------------------------------------------| |---------------------------------| |Example | | data one; | | do i=1 to 20; | | x=%_rannor(mean=2, std=1); | | %_rannor(seed=12345,var=y, mean=2, std=1); | | output; | | end; | | run; %print(one); | |Usage: %_rannor(seed=%sysfunc(datetime(), 15.), var=, mean=, std=, | | temp=_rannor0_); | \----------------------------------*/ %macro _rannor(seed=%sysfunc(datetime(), 15.), var=, mean=, std=, temp=_rannor0_); /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 3-22-2002 6:30pm; | | Purpose: Random Normal Generator; | \--------------------------------------------*/ %if (%quote(&seed) eq) %then %do; %put ==> Error: This is not a valid seed!; %if (%length(&var)) %then %do; &var=.; %end; %else %do; .;%end; %goto finish; %end; %else %do; %if (%length(&var)) %then %do; %if (not %sysfunc(rxmatch(%sysfunc(rxparse(_|.|$a|$A|$w)),&seed))) %then %do; drop &temp; retain &temp &seed; %let seed=&temp; %end; call rannor(&seed, &var); %if (%length(&mean.&std)) %then &var=&var; %end; %else rannor(&seed); %if (%length(&std)) %then *&std; %if (%length(&mean)) %then +&mean; %end; %finish: %mend _rannor;